const { model } = require('../db')
const schema = require('../schemas/stu')

// const stu = model( 'Student', schema ) 

class stuModel{ 
    constructor () { 
        this.db = model( 'Student', schema );
    }
    store ( data ) { 
        return this.db.insertMany( data );
    }
    find () { 
        return this.db.find();
    }
    del ( data ) { 

        return this.db.deleteOne( {_id:data});
    }
    update ( data ) { 
        // console.log(data);
        return this.db.updateOne( { _id: data.id }, { $set: { name: data.u_name, age: data.u_age, sex: data.u_sex, phone: data.u_phone, email: data.u_email } } );
         
        
    }
    search ( data ) { 
        return this.db.find( { name: data.name }, { _id: 0 } );
    }
    dim ( data ) { 
        let startDate = data.startTime;
        let endDate = data.endTime;
        console.log(startDate);
        let res = this.db.find( { date: { $gte: startDate, $lte: endDate } } );
        // console.log(res);
        return res;
    }
}
module.exports = new stuModel